home *** CD-ROM | disk | FTP | other *** search
Wrap
RRRRWWWWDDDDDDDDEEEEssssttttrrrreeeeaaaammmmbbbbuuuuffff((((3333CCCC++++++++)))) RRRRWWWWDDDDDDDDEEEEssssttttrrrreeeeaaaammmmbbbbuuuuffff((((3333CCCC++++++++)))) NNNNaaaammmmeeee RWDDEstreambuf - Rogue Wave library class SSSSyyyynnnnooooppppssssiiiissss #include <rw/winstrea.h> #include <iostream.h> iostream str( new RWDDEstreambuf(CF_TEXT, TRUE, TRUE, TRUE) ) ; DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn Class RRRRWWWWDDDDDDDDEEEEssssttttrrrreeeeaaaammmmbbbbuuuuffff is a specialized ssssttttrrrreeeeaaaammmmbbbbuuuuffff that gets and puts sequences of characters to Microsoft Windows global memory that has been allocated with the GGGGMMMMEEEEMMMM____DDDDDDDDEEEESSSSHHHHAAAARRRREEEE flag. It can be used to exchange data through the Windows DDDDyyyynnnnaaaammmmiiiicccc DDDDaaaattttaaaa EEEExxxxcccchhhhaaaannnnggggeeee (DDE) facility. The class has two modes of operation: dynamic and static. In dynamic mode, memory is allocated and reallocated on an as-needed basis. If too many characters are inserted into the internal buffer for its present size, then it will be resized and old characters copied over into any new memory as necessary. This is transparent to the user. It is expected that this mode would be used primarily by the DDE server. In static mode, the buffer streambuf is constructed from a specific piece of memory. No reallocations will be done. It is expected that this mode would be used primarily by the DDE client. In dynamic mode, the RRRRWWWWDDDDDDDDEEEEssssttttrrrreeeeaaaammmmbbbbuuuuffff "owns" any allocated memory until the member function ssssttttrrrr(((()))) is called, which "freezes" the buffer and returns an unlocked Windows handle to it. The effect of any further insertions is undefined. Until ssssttttrrrr(((()))) has been called, it is the responsibility of the RRRRWWWWDDDDDDDDEEEEssssttttrrrreeeeaaaammmmbbbbuuuuffff destructor to free any allocated memory. After the call to ssssttttrrrr(((()))), it becomes the user's responsibility. In static mode, the user always has the responsibility for freeing the memory handle. However, because the constructor locks and dereferences the handle, you should not free the memory until either the destructor or ssssttttrrrr(((()))) has been called, either of which will unlock the handle. Note that although the user may have the "responsibility" for freeing the memory, whether it is the client or the server that actually does the call to GGGGlllloooobbbbaaaallllFFFFrrrreeeeeeee(((()))) will depend on the DDE "release" flag. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee None EEEExxxxaaaammmmpppplllleeee This is an example of how the class might be used by a DDE server. #include <rw/winstrea.h> #include <iostream.h> #include <windows.h> #include <dde.h> BOOL PPPPaaaaggggeeee 1111 RRRRWWWWDDDDDDDDEEEEssssttttrrrreeeeaaaammmmbbbbuuuuffff((((3333CCCC++++++++)))) RRRRWWWWDDDDDDDDEEEEssssttttrrrreeeeaaaammmmbbbbuuuuffff((((3333CCCC++++++++)))) postToDDE(HWND hwndServer, HWND hwndClient) { RWDDEstreambuf* buf = new RWDDEstreambuf(CF_TEXT, TRUE, TRUE, TRUE); ostream ostr(buf); double d = 12.34; ostr << "Some text to be exchanged through the DDE.0; ostr << "The double you requested is: " << d << endl; ostr.put(0); // Include the terminating null // Lock the streambuf, get its handle: HANDLE hMem = buf->str(); // Get an identifying atom: ATOM aItem = GlobalAddAtom("YourData"); if(!PostMessage(hwndClient, WM_DDE_DATA, hwndServer, MAKELONG(hMem, aItem))){ // Whoops! The message post failed, perhaps because // the client terminated. Now we are responsible // for deallocating the memory: if( hMem != NULL ) GlobalFree(hMem); GlobalDeleteAtom(aItem); return FALSE; } return TRUE; } The handle of the DDE server is passed in as parameter hhhhwwwwnnnnddddSSSSeeeerrrrvvvveeeerrrr, the handle of the client as parameter hhhhwwwwnnnnddddCCCClllliiiieeeennnntttt. An oooossssttttrrrreeeeaaaammmm is created, using an RRRRWWWWDDDDDDDDEEEEssssttttrrrreeeeaaaammmmbbbbuuuuffff as its associated ssssttttrrrreeeeaaaammmmbbbbuuuuffff. The results can be used much like any other oooossssttttrrrreeeeaaaammmm, such as ccccoooouuuutttt, except that characters will be inserted into Windows global memory, from where they can be transferred through the DDE. Note the parameters used in the constructor. These should be studied below as they have important ramifications on how memory allocations are handled through the DDE. In particular, parameter ffffRRRReeeelllleeeeaaaasssseeee, if TTTTRRRRUUUUEEEE, states that the cccclllliiiieeeennnntttt will be responsible for deallocating the memory when done. The defaults also specify ffffAAAAcccckkkkRRRReeeeqqqq TTTTRRRRUUUUEEEE, meaning that the client will acknowledge receiving the message: you must be prepared to receive it. Some text and a double is inserted into the oooossssttttrrrreeeeaaaammmm. Member function ssssttttrrrr(((()))) is then called which unlocks and returns a Windows HHHHAAAANNNNDDDDLLLLEEEE. Once we have called ssssttttrrrr(((()))), we are responsible for this memory and must either free it when done, or pass on that responsibility to someone else. In this case, it will be passed on to the client. An atom is then constructed to identify the data. The DDE data, along with its identifying atom, is then posted. If the post fails, then we have been unable to foist our responsbility for the global memory onto someone else and will have to free it (along with the atom) ourselves. PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss RRRRWWWWDDDDDDDDEEEEssssttttrrrreeeeaaaammmmbbbbuuuuffff(WORD cfFormat = CF_TEXT, BOOL fResponse = TRUE BOOL fAckReq = TRUE PPPPaaaaggggeeee 2222 RRRRWWWWDDDDDDDDEEEEssssttttrrrreeeeaaaammmmbbbbuuuuffff((((3333CCCC++++++++)))) RRRRWWWWDDDDDDDDEEEEssssttttrrrreeeeaaaammmmbbbbuuuuffff((((3333CCCC++++++++)))) BOOL fRelease = TRUE); Constructs an empty RRRRWWWWDDDDDDDDEEEEssssttttrrrreeeeaaaammmmbbbbuuuuffff in dynamic mode. The results can be used anywhere any other ssssttttrrrreeeeaaaammmmbbbbuuuuffff can be used. Memory to accomodate new characters will be allocated as needed. The four parameters are as defined by the WWWWiiiinnnnddddoooowwwwssss RRRReeeeffffeeeerrrreeeennnncccceeee,,,, VVVVoooolllluuuummmmeeee 2222 (in particular, see the section DDDDDDDDEEEE MMMMeeeessssssssaaaaggggeeee DDDDiiiirrrreeeeccccttttoooorrrryyyy). Parameter ccccffffFFFFoooorrrrmmmmaaaatttt specifies the format of the data being inserted into the ssssttttrrrreeeeaaaammmmbbbbuuuuffff. These formats are the same as used by SSSSeeeettttCCCClllliiiippppbbbbooooaaaarrrrddddDDDDaaaattttaaaa(((()))). If a specializing virtual streams class such as RRRRWWWWbbbboooossssttttrrrreeeeaaaammmm or RRRRWWWWppppoooossssttttrrrreeeeaaaammmm is used to perform the actual character insertions instead of a simple oooossssttttrrrreeeeaaaammmm, the format may not be so simple. In this case, the user might want to register his or her own format, using the Windows function RRRReeeeggggiiiisssstttteeeerrrrCCCClllliiiippppbbbbooooaaaarrrrddddFFFFoooorrrrmmmmaaaatttt(((()))). For the meaning of the other three parameters see below, and/or the WWWWiiiinnnnddddoooowwwwssss reference manuals. RRRRWWWWDDDDDDDDEEEEssssttttrrrreeeeaaaammmmbbbbuuuuffff(HANDLE hMem); Constructs an RRRRWWWWDDDDDDDDEEEEssssttttrrrreeeeaaaammmmbbbbuuuuffff in static mode, using the memory block with global handle hhhhMMMMeeeemmmm. The effect of gets and puts beyond the size of this block is unspecified. The format of the DDE transfer, and the specifics of DDE acknowledgments, memory allocations, eeeettttcccc...., can be obtained by using the member functions defined below. PPPPuuuubbbblllliiiicccc DDDDeeeessssttttrrrruuuuccccttttoooorrrr ~RRRRWWWWDDDDDDDDEEEEssssttttrrrreeeeaaaammmmbbbbuuuuffff(); If member function ssssttttrrrr(((()))) has not been called, the destructor unlocks the handle and, if in dynamic mode, also frees it. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss Because RRRRWWWWDDDDDDDDEEEEssssttttrrrreeeeaaaammmmbbbbuuuuffff inherits from ssssttttrrrreeeeaaaammmmbbbbuuuuffff, any of the latter's member functions can be used. Furthermore, RRRRWWWWDDDDDDDDEEEEssssttttrrrreeeeaaaammmmbbbbuuuuffff has been designed to be analogous to ssssttttrrrreeeeaaaammmmbbbbuuuuffff. However, note that the return type of ssssttttrrrr(((()))) is a HHHHAAAANNNNDDDDLLLLEEEE, rather than a cccchhhhaaaarrrr****. BOOL aaaacccckkkkRRRReeeeqqqq() const; Returns whether this DDE exchange requests an acknowledgement. See the WWWWiiiinnnnddddoooowwwwssss RRRReeeeffffeeeerrrreeeennnncccceeee,,,, VVVVoooolllluuuummmmeeee 2222, for more information. WORD ffffoooorrrrmmmmaaaatttt() const; Returns the format of this DDE exchange (eeee....gggg...., CCCCFFFF____TTTTEEEEXXXXTTTT for text exchange, eeeettttcccc.). See the WWWWiiiinnnnddddoooowwwwssss RRRReeeeffffeeeerrrreeeennnncccceeee,,,, VVVVoooolllluuuummmmeeee 2222, for more information. PPPPaaaaggggeeee 3333 RRRRWWWWDDDDDDDDEEEEssssttttrrrreeeeaaaammmmbbbbuuuuffff((((3333CCCC++++++++)))) RRRRWWWWDDDDDDDDEEEEssssttttrrrreeeeaaaammmmbbbbuuuuffff((((3333CCCC++++++++)))) BOOL rrrreeeelllleeeeaaaasssseeee() const; Returns TTTTRRRRUUUUEEEE if the client is responsible for the release of of the memory returned by ssssttttrrrr(((()))). See the WWWWiiiinnnnddddoooowwwwssss RRRReeeeffffeeeerrrreeeennnncccceeee,,,, VVVVoooolllluuuummmmeeee 2222, for more information. BOOL rrrreeeessssppppoooonnnnsssseeee() const; Returns TTTTRRRRUUUUEEEE if this data is in response to a WWWWMMMM____DDDDDDDDEEEE____RRRREEEEQQQQUUUUEEEESSSSTTTT message. Otherwise, it is in response to a WWWWMMMM____DDDDDDDDEEEE____AAAADDDDVVVVIIIISSSSEEEE message. See the WWWWiiiinnnnddddoooowwwwssss RRRReeeeffffeeeerrrreeeennnncccceeee,,,, VVVVoooolllluuuummmmeeee 2222, for more information. HANDLE ssssttttrrrr(); Returns an (unlocked) HHHHAAAANNNNDDDDLLLLEEEE to the global memory being used. The RRRRWWWWDDDDDDDDEEEEssssttttrrrreeeeaaaammmmbbbbuuuuffff should now be regarded as "frozen": the effect of inserting any more characters is undefined. If the RRRRWWWWDDDDDDDDEEEEssssttttrrrreeeeaaaammmmbbbbuuuuffff was constructed in dynamic mode, and nothing has been inserted, then the returned HHHHAAAANNNNDDDDLLLLEEEE may be NNNNUUUULLLLLLLL. If it was constructed in static mode, then the returned handle will be the handle used to construct the RRRRWWWWDDDDDDDDEEEEssssttttrrrreeeeaaaammmmbbbbuuuuffff. PPPPaaaaggggeeee 4444